const path = require('path');
const webpackMerge = require('webpack-merge');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const baseConfig = require('./webpack.config.base.js');

const projectPath = require('./projectPath.js');
const devConfig = {
  output: {
    filename: 'js/built.[name].[hash:10].js',
  },
  mode: 'development',
  devtool: 'eval-source-map',
  module: {
    rules: [
      {
        oneOf: [
          {
            test: /\.css$/,
            use: ['style-loader', 'css-loader', 'postcss-loader']
          }
        ]
      }
    ]
  },
  plugins: [
    new HtmlWebpackPlugin({
      title: 'webpack html',
      template: path.resolve(projectPath, 'public', 'template.html'),
      filename: 'index.html'
    })
  ],
  devServer: {
    //项目路径
    contentBase: path.resolve(projectPath, 'dist'),
    //启动gzip压缩
    compress: true,
    //端口号
    port: 8000,
    //自动打开浏览器
    open: true,
    //开启HMR
    hot: true
  }
}
module.exports = webpackMerge(baseConfig, devConfig);